home *** CD-ROM | disk | FTP | other *** search
/ Graphics Plus / Graphics Plus.iso / general / procssng / ccs / ccs-11tl.lha / lbl / hips / sources / tools / rotate90n.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-09-23  |  1.9 KB  |  82 lines

  1. /* rotate90.c - rotate frames by 90 degrees
  2. *
  3. * usage: rotate90 [-right] [<] input [> output]
  4. *
  5. *    The -r switch rotates to the right (clockwise). The frames are rotated
  6. *    to the left (counterclockwise) in default.
  7. *
  8. * compile: cc -O4 -o rotate90 rotate90.c -lscs4 -lccs -lhips -lrle -ltiff
  9. *
  10. * AUTHOR:    Jin Guojun - LBL
  11. */
  12.  
  13. #include "header.def"
  14. #include "imagedef.h"
  15.  
  16. U_IMAGE    uimg;
  17.  
  18. #define    ibuf    uimg.src
  19. #define    obuf    uimg.dest
  20. #define    tbuf    uimg.cnvt
  21.  
  22. char    usage[] = "option\n\
  23. -r (==> turn to right. The default is to left--CounterClockWise)\n\
  24. [<] in_file [> output]\n";
  25.  
  26.  
  27. main(argc, argv)
  28. int    argc;
  29. char    *argv[];
  30. {
  31. bool    rflag=0, t2f;
  32. int    i, f, newr, newc, fsize;
  33.  
  34. format_init(&uimg, IMAGE_INIT_TYPE, HIPS, uimg.color_dpy=-1, *argv, "S20-2");
  35.  
  36. for (i=1; i<argc; i++)
  37.     if (*argv[i]=='-' && argv[i][1]=='r')    rflag++;
  38.     else if (! (in_fp=freopen(argv[i], "rb", stdin)) )
  39. errout:        usage_n_options(usage, i, argv[i]);
  40.  
  41. io_test(stdin_fd, goto    errout);
  42.  
  43. (*uimg.header_handle)(HEADER_READ, &uimg, 0, 0);
  44. (*uimg.header_handle)(HEADER_TRANSF, &uimg, 0);
  45. i = isColorImage(uimg.color_form);
  46. if (i > 1)
  47.     uimg.color_form = CFM_ILC;
  48. t2f = uimg.color_form==CFM_ILC;
  49.  
  50. if (uimg.in_form > IFMT_FLOAT)
  51.     prgmerr('f', "image must be in ints or float format");
  52. newc = uimg.height;
  53. newr = uimg.width;
  54.  
  55. uimg.sub_img_h = newr;
  56. uimg.sub_img_w = newc;
  57. fsize = newr * newc;
  58. uimg.sub_img = True;
  59.  
  60. uimg.update_header = (*uimg.header_handle)(HEADER_TO, &uimg, 0, No);
  61. (*uimg.header_handle)(HEADER_WRITE, &uimg, argc, argv, True);
  62.  
  63. obuf = nzalloc(fsize, uimg.pxl_out, "obuf");
  64.  
  65. i = uimg.pxl_in;
  66. uimg.load_all = 0;
  67.  
  68. for (f=0; f<uimg.frames; f++) {
  69.     (*uimg.std_swif)(FI_LOAD_FILE, &uimg, 0, No);
  70.     if (t2f)    {
  71.         tbuf = nzalloc(i=4, fsize, "tbuf");
  72.         ilc_transfer(tbuf, ibuf, fsize, 3, 0, i);
  73.         free(ibuf);    ibuf = tbuf;
  74.     }
  75.     rotate90(ibuf, obuf, newr, newc, i, rflag);
  76.     if (t2f)    ilc_transfer(obuf, obuf, fsize, 4, 0, i=3);
  77.     if (fwrite(obuf, i, fsize, out_fp) != fsize)
  78.         syserr("write");
  79. }
  80. exit(0);
  81. }
  82.